2020-2021 Sunseeker Telemetry and Lighting System
dma_ex3_singleTransferSPI.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
71 //******************************************************************************
72 
73 #include "driverlib.h"
74 
75 char TxString;
76 char RxString;
77 
78 void main (void)
79 {
80  //Initialize Watchdog in Interval Timer Mode
81  /*
82  * Base Address of WDT module
83  * Use ACLK as clock source to WDT module
84  * Divide ACLK by 32k to assert interval every 1 second
85  */
86  WDT_A_initIntervalTimer(WDT_A_BASE,
87  WDT_A_CLOCKSOURCE_ACLK,
88  WDT_A_CLOCKDIVIDER_32K);
89 
90  //Enable Watchdog Interupt
91  SFR_clearInterrupt(WDTIE);
92  SFR_enableInterrupt(WDTIE);
93 
94  //Clear P1.0 LED off
96 
97  GPIO_PORT_P1,
98  GPIO_PIN0
99  );
100 
101  //Set P1.0 to output direction
102  GPIO_setAsOutputPin(
103  GPIO_PORT_P1,
104  GPIO_PIN0
105  );
106 
107  //P3.4,3 & P2.7 option select
108  GPIO_setAsPeripheralModuleFunctionInputPin(
109  GPIO_PORT_P3,
110  GPIO_PIN4 + GPIO_PIN3
111  );
112  GPIO_setAsPeripheralModuleFunctionInputPin(
113  GPIO_PORT_P2,
114  GPIO_PIN7
115  );
116 
117  //Initialize Master
118  USCI_A_SPI_initMasterParam param = {0};
119  param.selectClockSource = USCI_A_SPI_CLOCKSOURCE_ACLK;
120  param.clockSourceFrequency = UCS_getACLK();
121  param.desiredSpiClock = 500000;
122  param.msbFirst = USCI_A_SPI_MSB_FIRST;
123  param.clockPhase = USCI_A_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT;
124  param.clockPolarity = USCI_A_SPI_CLOCKPOLARITY_INACTIVITY_HIGH;
125  USCI_A_SPI_initMaster(USCI_A0_BASE, &param);
126 
127  //Enable SPI module
128  USCI_A_SPI_enable(USCI_A0_BASE);
129 
130  //Wait for slave to init
131  __delay_cycles(100);
132 
133  //USCI_A0 TX buffer ready?
134  while (!USCI_A_SPI_getInterruptStatus(USCI_A0_BASE, UCTXIFG)) ;
135 
136 
137  //Initialize and Setup DMA Channel 0
138  /*
139  * Configure DMA channel 0
140  * Configure channel for single transfer
141  * DMA transfers will be disabled and interrupt flag will be set after every
142  * 1 transfer
143  * Use DMA Trigger Source 17 (UCA0TXIFG)
144  * Transfer Byte-to-byte
145  * Trigger transfer on signal held high
146  */
147  DMA_initParam param0 = {0};
148  param0.channelSelect = DMA_CHANNEL_0;
149  param0.transferModeSelect = DMA_TRANSFER_SINGLE;
150  param0.transferSize = 1;
151  param0.triggerSourceSelect = DMA_TRIGGERSOURCE_17;
152  param0.transferUnitSelect = DMA_SIZE_SRCBYTE_DSTBYTE;
153  param0.triggerTypeSelect = DMA_TRIGGER_HIGH;
154  DMA_init(&param0);
155  /*
156  * Configure DMA channel 0
157  * Use TxString as source
158  * Increment source address after every transfer
159  */
160  DMA_setSrcAddress(DMA_CHANNEL_0,
161  (uint32_t)(uintptr_t)&TxString,
162  DMA_DIRECTION_INCREMENT);
163  /*
164  * Configure DMA channel 0
165  * Use SPI TX Buffer as destination
166  * Don't move the destination address after every transfer
167  */
168  DMA_setDstAddress(DMA_CHANNEL_0,
169  USCI_A_SPI_getTransmitBufferAddressForDMA(USCI_A0_BASE),
170  DMA_DIRECTION_UNCHANGED);
171 
172  //Initialize and Setup DMA Channel 1
173  /*
174  * Configure DMA channel 1
175  * Configure channel for single transfer
176  * DMA transfers will be disabled and interrupt flag will be set after every
177  * 1 transfer
178  * Use DMA Trigger Source 16 (UCA0RXIFG)
179  * Transfer Byte-to-byte
180  * Trigger transfer on signal held high
181  */
182 
183  DMA_initParam param1 = {0};
184  param1.channelSelect = DMA_CHANNEL_1;
185  param1.transferModeSelect = DMA_TRANSFER_SINGLE;
186  param1.transferSize = 1;
187  param1.triggerSourceSelect = DMA_TRIGGERSOURCE_16;
188  param1.transferUnitSelect = DMA_SIZE_SRCBYTE_DSTBYTE;
189  param1.triggerTypeSelect = DMA_TRIGGER_HIGH;
190  DMA_init(&param1);
191 
192  /*
193  * Configure DMA channel 1
194  * Use SPI RX Buffer as source
195  * Don't move the source address after every transfer
196  */
197  DMA_setSrcAddress(DMA_CHANNEL_1,
198  USCI_A_SPI_getReceiveBufferAddressForDMA(USCI_A0_BASE),
199  DMA_DIRECTION_UNCHANGED);
200  /*
201  * Configure DMA channel 1
202  * Use RxString as destination
203  * Increment destination address after every transfer
204  */
205  DMA_setDstAddress(DMA_CHANNEL_1,
206  (uint32_t)(uintptr_t)&RxString,
207  DMA_DIRECTION_INCREMENT);
208 
209  //Clear TxString && RxString
210  TxString = RxString = 0;
211 
212  //Enter LPM3 w/ interrupts
213  __bis_SR_register(LPM3_bits + GIE);
214  //For Debugger
215  __no_operation();
216 }
217 
218 //------------------------------------------------------------------------------
219 //Trigger DMA0 & DMA1 block transfer.
220 //------------------------------------------------------------------------------
221 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
222 #pragma vector=WDT_VECTOR
223 __interrupt
224 #elif defined(__GNUC__)
225 __attribute__((interrupt(WDT_VECTOR)))
226 #endif
227 void WDT_A_ISR (void)
228 {
229  if (TxString - 1 == RxString){
230  //set P1.0
232 
233  GPIO_PORT_P1,
234  GPIO_PIN0
235  );
236  } else {
237  //Clear P1.0 LED off
239 
240  GPIO_PORT_P1,
241  GPIO_PIN0
242  );
243  }
244 
245  //Increment TxString counter
246  TxString++;
247 
248  //Enable DMA transfers on channel 1
249  DMA_enableTransfers(DMA_CHANNEL_1);
250 
251  //Enable DMA transfers on channel 0
252  DMA_enableTransfers(DMA_CHANNEL_0);
253 }
254 
MPU_initThreeSegmentsParam param
void main(void)
void WDT_A_ISR(void)
__no_operation()
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)